procedure gm(k:longint); {ALL Vertexes} {K - number of iteration; A - matrix; St - array for way of vertex search; Nnew - array of boolean (visited or not)}
var v,j:longint;
begin
v:=st[k-1];
for j:=1 to n do begin
  if a[i][j]<>0 then if (k=n+1) and (j=1) then exit else
  if nnew[j] then begin
    st[k]:=j;
    nnew[j]:=false;
    gm(k+1);
    nnew[j]:=true;
  end;
end;
end;